<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>checkbox</title>
    <link rel="stylesheet" href="../common.css">
    <style>
        :root{
            --checked: orange;
        }
        .container{
            min-width: 280px;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0,0,0,0.3);
            position: relative;
        }
        .item{
            margin-bottom: 20px;
            font-size: 15px;
            letter-spacing: 5px;
        }
        .item:last-child{
            margin-bottom: 0;
        }
        input[type='checkbox']{
            /* 去除系统默认 */
            -webkit-appearance: none;
            appearance: none;

            width: 25px;
            height: 25px;
            position: relative;
            margin-right: 10px;
        }
        input[type="checkbox"]::after{
            content: "";
            width: 100%;
            height: 100%;
            border: 2px solid #fff;
            position: absolute;
            left: 0;
            top: 0;
            border-radius: 50%;
            transition: all 0.5s ease-in-out;
        }
        input[type="checkbox"]:checked::after{
            height: 15px;
            width: 25px;
            border: 2px solid var(--checked);
            border-top: none;
            border-right: none;
            border-radius: 0;
            transform: rotate(-45deg);
            transition: all 0.5s ease-in-out;
        }
        label{
            cursor: pointer;
            text-decoration-line: underline;
            /* 底部线条透明 */
            text-decoration-color: transparent;
            text-underline-offset: 1px;

            transition: all 0.5s;
        }
        label:hover{
            text-decoration-color: var(--checked);
            text-underline-offset: 10px;
            color: var(--checked);
        }
        input[type="checkbox"]:checked + label{
            color: var(--checked);
            text-underline-offset: -5px;
            text-decoration-color: var(--checked);
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="item">
            <input type="checkbox" class="option1">
            <label for="option1">吃饭</label>
        </div>
        <div class="item">
            <input type="checkbox" class="option2">
            <label for="option2">睡觉</label>
        </div>
        <div class="item">
            <input type="checkbox" class="option3">
            <label for="option3">打豆豆</label>
        </div>
    </div>
    <script>
        let items = document.querySelectorAll(".item label");
        for(let i of items){
            i.addEventListener("click",()=>{
                i.parentNode.querySelector("input").checked = !i.parentNode.querySelector("input").checked;
            })
        }
    </script>
</body>
</html>